home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-05-26 | 9.0 KB | 241 lines | [MSBA/MSBA] |
- 10 REM File Comparison Program. Copyright 1984 John W. Baxter.
- 40 REM Input: Two files, which can be processed by BASIC as text files.
- 50 REM Output: A listing of the differences, on a line-by-line basis,
- 60 REM between the input files.
- 70 REM The program attempts to handle cases in which extra lines
- 80 REM exist in one of the files, by searching both files until equal lines
- 90 REM are discovered.
- 100 GOTO 1000
- 500 REM Get next line from file IFILE.
- 510 IF IGET(IFILE) THEN 600
- 520 LINE INPUT #IFILE, TNEXT(IFILE)
- 530 GOTO 630
- 600 TNEXT(IFILE)=T(IFILE, FIRST(IFILE))
- 602 T(IFILE, FIRST(IFILE))=""
- 610 FIRST(IFILE)=FIRST(IFILE)+1
- 620 IF FIRST(IFILE)<=LIMIT(IFILE) THEN 630
- 622 IGET(IFILE)=0: FIRST(IFILE)=0: LIMIT(IFILE)=0
- 630 COUNT(IFILE)=COUNT(IFILE)+1
- 640 RETURN
- 700 REM Print a line TPRINT, with line number LINENO.
- 702 FOR C=1 TO LEN(TPRINT)
- 704 IF MID$(TPRINT, C, 1) < " " THEN MID$(TPRINT, C, 1) = TCONTROL
- 706 NEXT
- 710 PRINT #LFILE, USING "#,### &"; LINENO, TPRINT
- 720 RETURN
- 730 REM Enhance for control chars & special cases.
- 1000 CLS
- 1002 CLEAR ,24000
- 1010 PRINT: PRINT "Text file compare. Copyright "; CHR$(169);
- 1012 PRINT "1984 John W. Baxter"
- 1020 PRINT"Version 1.2"; CHR$(167); " Last updated June 14, 1984 at 2115"
- 1030 REM Watch out for the following!
- 1040 DEFINT I-K: DEFSTR T
- 1042 OPTION BASE 1
- 1050 GOSUB 50000: REM Variable definitions
- 1060 GOSUB 40000: REM User input routine (file names, parameters)
- 1068 PRINT #LFILE,
- 1070 PRINT #LFILE, "Compare "; TNAME(1); " and "; TNAME(2);
- 1080 PRINT #LFILE, " on "; DATE$; " at "; TIME$
- 1100 REM Files are in synch
- 1110 WHILE (NOT EOF(1)) AND (NOT EOF(2))
- 1120 FOR IFILE=1 TO 2: GOSUB 500: NEXT
- 1130 IF TNEXT(1)<>TNEXT(2) THEN GOSUB 2000
- 1140 WEND
- 1150 FOR IFILE=1 TO 2
- 1160 IF NOT EOF(IFILE) THEN GOSUB 3000: REM Report extra lines.
- 1170 NEXT
- 1180 CLOSE
- 1190 PRINT: PRINT "Compare completed. ";
- 1192 IF ISDIF THEN PRINT "Check differences."
- 1200 IF ISSCREEN AND ISDIF THEN PRINT: PRINT
- 1210 END
- 2000 REM Process file difference other than extra text at end
- 2010 FOR I=1 TO 2
- 2020 BOTTOM(I)=COUNT(I)
- 2030 T(I,1)=TNEXT(I)
- 2040 LAST(I)=1
- 2050 NEXT
- 2060 REM UNTIL Resynchronized or out of space in arrays
- 2070 IFILE=1: JFILE=2
- 2080 REM REPEAT
- 2090 IF EOF (IFILE) THEN 2100
- 2092 GOSUB 500
- 2094 LAST(IFILE)=LAST(IFILE)+1
- 2096 T(IFILE, LAST(IFILE))=TNEXT(IFILE)
- 2100 REM Single-line resynch test only.
- 2110 I=1
- 2120 IF TNEXT(IFILE)=T(JFILE,I) THEN 2200
- 2130 I=I+1
- 2140 IF I<= LAST(JFILE) THEN 2120
- 2150 IF EOF(IFILE) AND EOF (JFILE) THEN 2800
- 2160 IF LAST(IFILE)=MAXLINES THEN 2500
- 2170 SWAP IFILE,JFILE
- 2180 GOTO 2090: REM UNTIL Resynchronized {or out of array space}
- 2200 REM Resynchronized by matching line.
- 2210 IF I=1 THEN 2600: REM Extra text between lines.
- 2212 ISDIF=1
- 2220 PRINT #LFILE,: PRINT #LFILE, "Difference:"
- 2222 PRINT #LFILE, "Lines from "; TNAME(IFILE); ":"
- 2230 FOR J=1 TO LAST(IFILE)-1
- 2240 LINENO=BOTTOM(IFILE)+J-1: TPRINT= T(IFILE,J): GOSUB 700
- 2242 T(IFILE, J)=""
- 2250 NEXT
- 2260 PRINT #LFILE, "Lines from "; TNAME(JFILE); ":"
- 2270 FOR J=1 TO I-1
- 2280 LINENO=BOTTOM(JFILE)+J-1: TPRINT= T(JFILE,J): GOSUB 700
- 2282 T(JFILE, J)=""
- 2290 NEXT
- 2300 IF I=LAST(JFILE) THEN RETURN
- 2310 COUNT(JFILE)=BOTTOM(JFILE)+I-1: BOTTOM(JFILE)=COUNT(JFILE)+1
- 2320 FOR J=1 TO LAST(JFILE)-I
- 2330 T(JFILE,J)=T(JFILE,I+J)
- 2340 T(JFILE,I+J)=""
- 2350 NEXT
- 2358 IF FIRST(JFILE)=0 THEN 2410
- 2360 WHILE FIRST(JFILE)<=LIMIT(JFILE)
- 2370 T(JFILE,J)=T(JFILE,FIRST(JFILE))
- 2380 T(JFILE,FIRST(JFILE))=""
- 2390 J=J+1: FIRST(JFILE)=FIRST(JFILE)+1
- 2400 WEND
- 2410 LIMIT(JFILE)=J-1: FIRST(JFILE)=1
- 2420 IGET(JFILE)=1
- 2430 RETURN
- 2500 REM Too much difference to resynchronize. Temporary: Give up!
- 2510 PRINT #LFILE, : PRINT #LFILE, "Files are too different to report!"
- 2520 ISDIF=1
- 2530 GOTO 1180
- 2600 REM Report extra text in IFILE between lines of JFILE
- 2610 PRINT #LFILE, : PRINT #LFILE, "Extra text on "; TNAME(IFILE);
- 2612 PRINT #LFILE, ", between lines"; BOTTOM(JFILE)-1;
- 2613 PRINT #LFILE, "and"; BOTTOM(JFILE);
- 2614 PRINT #LFILE, "of "; TNAME(JFILE)
- 2618 ISDIF=1
- 2620 FOR I=1 TO LAST(IFILE)-1
- 2630 LINENO=BOTTOM(IFILE)+I-1: TPRINT=T(IFILE,I): GOSUB 700
- 2640 T(IFILE,I)=""
- 2650 NEXT
- 2680 FOR J=1 TO LAST(JFILE)-1
- 2690 T(JFILE,J)=T(JFILE,J+1)
- 2700 NEXT
- 2710 T(JFILE,J)=""
- 2720 WHILE (FIRST(JFILE)>0) AND (FIRST(JFILE)<=LIMIT(JFILE))
- 2730 T(JFILE,J)=T(JFILE,FIRST(JFILE)): T(JFILE, FIRST(JFILE))=""
- 2740 J=J+1: FIRST(JFILE)=FIRST(JFILE)+1
- 2750 WEND
- 2760 LIMIT(JFILE)=J-1
- 2780 IF LIMIT(JFILE)>0 THEN 2786
- 2782 FIRST(JFILE)=0: IGET(JFILE)=0: GOTO 2790
- 2786 FIRST(JFILE)=1: IGET(JFILE)=1
- 2787 COUNT(JFILE)=BOTTOM(JFILE)
- 2788 BOTTOM(JFILE)=COUNT(JFILE)+1
- 2790 RETURN
- 2800 REM Both files have End of File, and a resynchronize is in progress.
- 2810 PRINT #LFILE,: PRINT #LFILE, "Difference: non-matching ";
- 2812 PRINT #LFILE, "lines at ends of the files."
- 2820 ISDIF=1
- 2830 FOR IFILE=1 TO 2
- 2840 PRINT #LFILE, "Lines from "; TNAME(IFILE); ":"
- 2850 FOR I=1 TO LAST(IFILE)
- 2860 LINENO=BOTTOM(IFILE)+I-1: TPRINT=T(IFILE,I): GOSUB 700
- 2870 T(IFILE,I)=""
- 2880 NEXT
- 2890 IF IFILE=1 THEN PRINT#LFILE,
- 2900 NEXT
- 2910 RETURN
- 3000 REM Display extra text on end of an input file.
- 3010 ISDIF=1
- 3020 PRINT #LFILE,
- 3022 PRINT #LFILE, "Extra text on end of file "; TNAME(IFILE); ":"
- 3030 WHILE NOT EOF(IFILE)
- 3040 GOSUB 500
- 3050 LINENO=COUNT(IFILE): TPRINT= TNEXT(IFILE): GOSUB 700
- 3060 WEND
- 3070 RETURN
- 40000 REM Temporary user interaction. Hopefully, to be replaced by a
- 40010 REM pseudo-dialog box.
- 40020 IFILE=1
- 40030 GOSUB 41000: REM get file name for file 1.
- 40040 IFILE=2
- 40050 GOSUB 41000: REM Get file name for file 2.
- 40060 GOSUB 42000: REM Get other user input
- 40070 FOR I=1 TO 2
- 40080 ON ERROR GOTO 40200
- 40090 OPEN TNAME(I) FOR INPUT AS #I
- 40100 ON ERROR GOTO 0
- 40110 NEXT
- 40120 ON ERROR GOTO 40300
- 40130 OPEN TOUT FOR OUTPUT AS #LFILE
- 40140 ON ERROR GOTO 0
- 40148 GOSUB 40400: REM Determine whether output is SCRN:
- 40150 IF ISSCREEN THEN WIDTH#LFILE, 60 ELSE WIDTH#LFILE,79
- 40160 RETURN
- 40200 REM Error routine for opening input file
- 40210 IF ERL<>40090 THEN ON ERROR GOTO 0: REM Let BASIC handle it.
- 40220 IF ERR<>53 THEN ON ERROR GOTO 0: REM Let BASIC handle it.
- 40230 IFILE=I
- 40240 BEEP: PRINT: PRINT "File "; TNAME(IFILE); " not found."
- 40250 LINE INPUT "Re-enter file name: "; TNAME(IFILE)
- 40260 RESUME 40090
- 40300 REM Error routine for opening output file
- 40310 IF ERL<>40130 THEN ON ERROR GOTO 0: REM Let BASIC handle it.
- 40320 BEEP: PRINT: PRINT "Cannot open "; TOUT; " as output."
- 40330 LINE INPUT "Re-enter file or device name: "; TOUT
- 40340 RESUME 40130
- 40400 FOR I=1 TO LEN(TOUT)
- 40410 T=MID$(TOUT, I, 1)
- 40420 IF (T>="a") AND (T<="z") THEN MID$(TOUT, I, 1)= CHR$(ASC(T)-32)
- 40430 NEXT
- 40440 ISSCREEN = (TOUT="SCRN:")
- 40442 IF ISSCREEN THEN WIDTH #LFILE, 60 ELSE WIDTH #LFILE, 79
- 40444 IF ISSCREEN THEN TCONTROL=CHR$(165) ELSE TCONTROL = "~"
- 40450 RETURN
- 41000 REM Routine to input an input file name
- 41010 PRINT "Enter name of input file "; ID$(IFILE); ": ";
- 41020 LINE INPUT TNAME(IFILE)
- 41030 RETURN
- 42000 REM Stub: gets user input of output target, sets resynch to 1
- 42010 TOUT="scrn:"
- 42020 PRINT "Send output to:"
- 42030 PRINT " 1 Screen"
- 42040 PRINT " 2 Printer"
- 42050 PRINT " 3 File or other device"
- 42060 LINE INPUT " Enter choice: "; TOUT
- 42070 IF TOUT="" THEN I=1 ELSE I=VAL(TOUT)
- 42080 IF I<1 OR I>3 THEN BEEP: GOTO 42060
- 42090 ON I GOTO 42100,42200,42300
- 42100 TOUT="SCRN:"
- 42120 GOTO 42500
- 42200 TOUT="LPT1:"
- 42220 GOTO 42500
- 42300 LINE INPUT "Enter file or device name: "; TOUT
- 42500 RESYNCH=1
- 42510 RETURN
- 50000 REM The following defines and describes all program variables.
- 50010 MAXLINES=100: REM Maximum line indices for resynch attempt
- 50020 REM Above must be equal to the second dimension below.
- 50030 DIM T(2,100): REM Holds up to 100 out-of-synch lines per file
- 50040 DIM TNEXT(2): REM Holds current line for each file
- 50050 DIM COUNT(2): REM Line counter for each file
- 50060 DIM BOTTOM(2): REM Line number for T(x,1), when T in use.
- 50070 DIM PTR(2): REM Index into T(x,...)
- 50080 DIM LIMIT(2): REM Highest T(x,...) in use by input routine.
- 50090 DIM FIRST(2): REM Lowest T(x,...) in use by input routine.
- 50092 DIM LAST(2): REM Highest T(x,...) in use by resynch routine.
- 50100 I=0: J=0: REM General integer counters
- 50110 IFILE=0: REM Selects FILE 1 or 2, for input routine, etc
- 50112 JFILE=0: REM Resynch routine keeps this the opposite of IFILE
- 50120 DIM IGET(2): REM IGET(x) true when "input" from T(x)
- 50130 LFILE=3: REM File number for output
- 50140 DIM TNAME(2): REM Names of the input files
- 50150 TOUT="": REM Name of the output file or device
- 50152 T="": REM Used as temporary in user input routine.
- 50160 ISDIF=0: REM TRUE when differences have been found.
- 50170 ISSCREEN=0: REM TRUE when output is to SCRN:
- 50180 RESYNCH=0: REM Number of lines which must match for resynch
- 50190 DIM ID$(2): REM Array to identify input files
- 50200 ID$(1)="one": ID$(2)="two"
- 50210 TCONTROL=CHR$(165): REM The center dot character
- 50220 C=0: REM Character index for control char removal
- 50990 RETURN
-